

function say() {
    alert("LC:128. 最长连续序列");
}
say();


var longestConsecutive = function (nums) {
    //5:20-35

    var setNum = new Set(nums)

    var res = 0
    for (var i = 0; i < nums.length; i++) {
        if (!setNum.has(nums[i] - 1)) { //没有前一个元素;是头
            var current = nums[i]
            var gap = 1
            while (setNum.has(current + gap)) {
                // current++
                gap++
            }
            res = res > gap ? res : gap
        }
    }
    return res
};


// https://leetcode-cn.com/problems/longest-consecutive-sequence/solution/fang-fa-cong-yi-dao-nan-bing-cha-ji-fang-fa-bu-hui/
